﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventScavenger
{
    public partial class ReaperEdit : Form
    {
        public ReaperEdit()
        {
            InitializeComponent();
        }

        public Reaper SelectedReaper { get; set; }

        private void ReaperEdit_Load(object sender, EventArgs e)
        {
            if (SelectedReaper != null)
            {
                txtServerName.Text = SelectedReaper.ServerName;
            }
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtServerName.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must specify a server name!", "Server name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtServerName.Focus();
            }
            else if (!PingHelper.IsOffline() && !PingHelper.CanPingHost(txtServerName.Text) &&
                    MessageBox.Show("Specified server name cannot be accessed on the network!\r\nPlease check network connectivity and server name.\r\nAccept anyway?", "Server name", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
            {
                txtServerName.Focus();
            }
            else
            {
                if (SelectedReaper == null)
                {
                    SelectedReaper = new Reaper()
                    {
                        ReaperId = 0,
                        ServerName = txtServerName.Text
                    };
                }
                else
                {
                    SelectedReaper.ServerName = txtServerName.Text;
                }
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }


    }
}
